﻿using DotNetFunctionDemo.CusAttribute;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace DotNetFunctionDemo.CommonLib
{
    public class ReflectionHelp
    {
        public static MemberInfo[] PrintMemberInfo<T>(T obj)
        {

            //var props = from p in MappedType.GetRuntimeProperties()
            //            where ((p.GetMethod != null && p.GetMethod.IsPublic) || (p.SetMethod != null && p.SetMethod.IsPublic) || (p.GetMethod != null && p.GetMethod.IsStatic) || (p.SetMethod != null && p.SetMethod.IsStatic))
            //            select p;
            //得到所有成员，field property method constructor
            MemberInfo[] mInfos = typeof(T).GetMembers(BindingFlags.Instance | BindingFlags.Public| BindingFlags.NonPublic | BindingFlags.Static);
            return mInfos;
        }

        public static IEnumerable<MethodInfo> ExecuteMethodOfAttribute(string method)
        {
            var info = typeof(ReflectionClass).GetMethods().Where(m => m.CustomAttributes.Any(c => c.AttributeType == typeof(AjaxAction)));
            return info;
        }

    }
    public class ReflectionClass
    {
        public int pubp { get; set; }
        private int prip { get; set; }

        private int priF = 0;
        public int pubF = 0;

        public int AddMethod(int a)
        {
            return a + 2;
        }

        private int AddMethodPri(int a)
        {
            return a + 2;
        }
        [AjaxAction("test")]
        public int AddMethodOfAttribute(int a)
        {
            return a + 2;
        }


        public static readonly int SUMStaticP = 0;
        public Student stPObj = new Student();
    }

}
